package com.lei2j.iterator;

import java.util.ArrayList;
import java.util.List;

public class Menu extends MenuComponent {
	
	private String name;
	
	private String description;
	
	List<MenuComponent> items;
	
	public Menu(String name, String description) {
		super();
		this.name = name;
		this.description = description;
		this.items = new ArrayList<>(0);
	}

	@Override
	public String getName() {
		return this.name;
	}

	@Override
	public String getDesciption() {
		return this.description;
	}

	@Override
	public void print() {
		System.out.println(String.format("Name:%s,Description:%s", this.name, this.description));
		java.util.Iterator<MenuComponent> iterator = items.iterator();
		while (iterator.hasNext()) {
			MenuComponent next = iterator.next();
			next.print();
		}
	}

	@Override
	public boolean add(MenuComponent component) {
		return items.add(component);
	}

	@Override
	public boolean remove(MenuComponent component) {
		return items.remove(component);
	}

	@Override
	public MenuComponent getChild(int index) {
		if (index < 0 || index >= items.size()) {
			throw new IndexOutOfBoundsException();
		}
		return items.get(index);
	}

	@Override
	public Iterator<MenuComponent> iterator() {
		return null;
	}
}
